package org.dromara.yuanshidian.service.impl;

import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.dromara.yuanshidian.domain.bo.Ab15Bo;
import org.dromara.yuanshidian.domain.vo.Ab15Vo;
import org.dromara.yuanshidian.domain.Ab15;
import org.dromara.yuanshidian.mapper.Ab15Mapper;
import org.dromara.yuanshidian.service.IAb15Service;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 个人账户基金转入转出信息（转出转入人员）Service业务层处理
 *
 * @author Lion Li
 * @date 2025-01-24
 */
@RequiredArgsConstructor
@Service
public class Ab15ServiceImpl implements IAb15Service {

    private final Ab15Mapper baseMapper;

    /**
     * 查询个人账户基金转入转出信息（转出转入人员）
     *
     * @param id 主键
     * @return 个人账户基金转入转出信息（转出转入人员）
     */
    @Override
    public Ab15Vo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 分页查询个人账户基金转入转出信息（转出转入人员）列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 个人账户基金转入转出信息（转出转入人员）分页列表
     */
    @Override
    public TableDataInfo<Ab15Vo> queryPageList(Ab15Bo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<Ab15> lqw = buildQueryWrapper(bo);
        Page<Ab15Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询符合条件的个人账户基金转入转出信息（转出转入人员）列表
     *
     * @param bo 查询条件
     * @return 个人账户基金转入转出信息（转出转入人员）列表
     */
    @Override
    public List<Ab15Vo> queryList(Ab15Bo bo) {
        LambdaQueryWrapper<Ab15> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<Ab15> buildQueryWrapper(Ab15Bo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<Ab15> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getAaa027()), Ab15::getAaa027, bo.getAaa027());
        lqw.eq(StringUtils.isNotBlank(bo.getBj()), Ab15::getBj, bo.getBj());
        lqw.eq(StringUtils.isNotBlank(bo.getBj00()), Ab15::getBj00, bo.getBj00());
        lqw.eq(bo.getBj01() != null, Ab15::getBj01, bo.getBj01());
        lqw.eq(bo.getBj02() != null, Ab15::getBj02, bo.getBj02());
        lqw.eq(bo.getBj03() != null, Ab15::getBj03, bo.getBj03());
        lqw.eq(StringUtils.isNotBlank(bo.getBj04()), Ab15::getBj04, bo.getBj04());
        lqw.eq(bo.getBj05() != null, Ab15::getBj05, bo.getBj05());
        lqw.eq(StringUtils.isNotBlank(bo.getGr01()), Ab15::getGr01, bo.getGr01());
        lqw.eq(StringUtils.isNotBlank(bo.getGr02()), Ab15::getGr02, bo.getGr02());
        lqw.eq(StringUtils.isNotBlank(bo.getGr03()), Ab15::getGr03, bo.getGr03());
        lqw.eq(StringUtils.isNotBlank(bo.getGr04()), Ab15::getGr04, bo.getGr04());
        lqw.eq(StringUtils.isNotBlank(bo.getGr05()), Ab15::getGr05, bo.getGr05());
        lqw.eq(StringUtils.isNotBlank(bo.getGr06()), Ab15::getGr06, bo.getGr06());
        lqw.eq(bo.getGr07() != null, Ab15::getGr07, bo.getGr07());
        lqw.eq(bo.getGr08() != null, Ab15::getGr08, bo.getGr08());
        lqw.eq(StringUtils.isNotBlank(bo.getGr09()), Ab15::getGr09, bo.getGr09());
        lqw.eq(bo.getGr10() != null, Ab15::getGr10, bo.getGr10());
        lqw.eq(bo.getGr11() != null, Ab15::getGr11, bo.getGr11());
        lqw.eq(bo.getGr12() != null, Ab15::getGr12, bo.getGr12());
        lqw.eq(bo.getGr13() != null, Ab15::getGr13, bo.getGr13());
        lqw.eq(bo.getGr14() != null, Ab15::getGr14, bo.getGr14());
        lqw.eq(bo.getGr15() != null, Ab15::getGr15, bo.getGr15());
        lqw.eq(bo.getGr16() != null, Ab15::getGr16, bo.getGr16());
        lqw.eq(bo.getGr17() != null, Ab15::getGr17, bo.getGr17());
        lqw.eq(bo.getGr18() != null, Ab15::getGr18, bo.getGr18());
        lqw.eq(bo.getGr19() != null, Ab15::getGr19, bo.getGr19());
        lqw.eq(bo.getGr20() != null, Ab15::getGr20, bo.getGr20());
        lqw.eq(bo.getGr21() != null, Ab15::getGr21, bo.getGr21());
        lqw.eq(bo.getGr60() != null, Ab15::getGr60, bo.getGr60());
        lqw.eq(StringUtils.isNotBlank(bo.getYd02()), Ab15::getYd02, bo.getYd02());
        lqw.eq(StringUtils.isNotBlank(bo.getYd03()), Ab15::getYd03, bo.getYd03());
        lqw.eq(StringUtils.isNotBlank(bo.getYd08()), Ab15::getYd08, bo.getYd08());
        lqw.eq(StringUtils.isNotBlank(bo.getYd05()), Ab15::getYd05, bo.getYd05());
        lqw.eq(StringUtils.isNotBlank(bo.getDw01()), Ab15::getDw01, bo.getDw01());
        lqw.eq(StringUtils.isNotBlank(bo.getDw02()), Ab15::getDw02, bo.getDw02());
        lqw.eq(StringUtils.isNotBlank(bo.getDw04()), Ab15::getDw04, bo.getDw04());
        lqw.eq(StringUtils.isNotBlank(bo.getDw07()), Ab15::getDw07, bo.getDw07());
        lqw.eq(StringUtils.isNotBlank(bo.getDw27()), Ab15::getDw27, bo.getDw27());
        lqw.eq(bo.getZy01() != null, Ab15::getZy01, bo.getZy01());
        lqw.eq(StringUtils.isNotBlank(bo.getDw08()), Ab15::getDw08, bo.getDw08());
        lqw.eq(StringUtils.isNotBlank(bo.getYd07()), Ab15::getYd07, bo.getYd07());
        lqw.eq(StringUtils.isNotBlank(bo.getZy02()), Ab15::getZy02, bo.getZy02());
        lqw.eq(StringUtils.isNotBlank(bo.getZy03()), Ab15::getZy03, bo.getZy03());
        lqw.eq(StringUtils.isNotBlank(bo.getZy04()), Ab15::getZy04, bo.getZy04());
        lqw.eq(StringUtils.isNotBlank(bo.getZy05()), Ab15::getZy05, bo.getZy05());
        lqw.eq(bo.getZy06() != null, Ab15::getZy06, bo.getZy06());
        lqw.eq(StringUtils.isNotBlank(bo.getZy07()), Ab15::getZy07, bo.getZy07());
        lqw.eq(bo.getZy17() != null, Ab15::getZy17, bo.getZy17());
        lqw.eq(StringUtils.isNotBlank(bo.getZy19()), Ab15::getZy19, bo.getZy19());
        lqw.eq(StringUtils.isNotBlank(bo.getZy20()), Ab15::getZy20, bo.getZy20());
        lqw.eq(StringUtils.isNotBlank(bo.getZy21()), Ab15::getZy21, bo.getZy21());
        lqw.eq(StringUtils.isNotBlank(bo.getZy22()), Ab15::getZy22, bo.getZy22());
        lqw.eq(StringUtils.isNotBlank(bo.getZy23()), Ab15::getZy23, bo.getZy23());
        lqw.eq(bo.getZy24() != null, Ab15::getZy24, bo.getZy24());
        lqw.eq(bo.getZy25() != null, Ab15::getZy25, bo.getZy25());
        lqw.eq(bo.getZy26() != null, Ab15::getZy26, bo.getZy26());
        lqw.eq(bo.getZy27() != null, Ab15::getZy27, bo.getZy27());
        lqw.eq(bo.getZy28() != null, Ab15::getZy28, bo.getZy28());
        lqw.eq(bo.getZy29() != null, Ab15::getZy29, bo.getZy29());
        lqw.eq(bo.getZy30() != null, Ab15::getZy30, bo.getZy30());
        lqw.eq(bo.getZy31() != null, Ab15::getZy31, bo.getZy31());
        lqw.eq(bo.getZy32() != null, Ab15::getZy32, bo.getZy32());
        lqw.eq(bo.getZy33() != null, Ab15::getZy33, bo.getZy33());
        lqw.eq(bo.getZy34() != null, Ab15::getZy34, bo.getZy34());
        lqw.eq(bo.getGrzh01() != null, Ab15::getGrzh01, bo.getGrzh01());
        lqw.eq(bo.getGrzh02() != null, Ab15::getGrzh02, bo.getGrzh02());
        lqw.eq(bo.getGrzh03() != null, Ab15::getGrzh03, bo.getGrzh03());
        lqw.eq(bo.getGrzh04() != null, Ab15::getGrzh04, bo.getGrzh04());
        lqw.eq(bo.getGrzh05() != null, Ab15::getGrzh05, bo.getGrzh05());
        lqw.eq(bo.getGrzh06() != null, Ab15::getGrzh06, bo.getGrzh06());
        lqw.eq(bo.getGrzh08() != null, Ab15::getGrzh08, bo.getGrzh08());
        lqw.eq(bo.getGrzh11() != null, Ab15::getGrzh11, bo.getGrzh11());
        lqw.eq(bo.getGrzh14() != null, Ab15::getGrzh14, bo.getGrzh14());
        lqw.eq(bo.getGrzh16() != null, Ab15::getGrzh16, bo.getGrzh16());
        lqw.eq(bo.getGrzh17() != null, Ab15::getGrzh17, bo.getGrzh17());
        lqw.eq(bo.getGrzh18() != null, Ab15::getGrzh18, bo.getGrzh18());
        lqw.eq(bo.getGrzh19() != null, Ab15::getGrzh19, bo.getGrzh19());
        lqw.eq(StringUtils.isNotBlank(bo.getSz01()), Ab15::getSz01, bo.getSz01());
        lqw.eq(bo.getDw21() != null, Ab15::getDw21, bo.getDw21());
        lqw.eq(StringUtils.isNotBlank(bo.getDh()), Ab15::getDh, bo.getDh());
        lqw.eq(StringUtils.isNotBlank(bo.getDw24()), Ab15::getDw24, bo.getDw24());
        lqw.eq(bo.getSystime() != null, Ab15::getSystime, bo.getSystime());
        lqw.eq(StringUtils.isNotBlank(bo.getGr62()), Ab15::getGr62, bo.getGr62());
        lqw.eq(StringUtils.isNotBlank(bo.getGr63()), Ab15::getGr63, bo.getGr63());
        lqw.eq(bo.getGrjx09() != null, Ab15::getGrjx09, bo.getGrjx09());
        lqw.eq(bo.getXh() != null, Ab15::getXh, bo.getXh());
        lqw.eq(StringUtils.isNotBlank(bo.getZy071()), Ab15::getZy071, bo.getZy071());
        lqw.eq(StringUtils.isNotBlank(bo.getGrjx01()), Ab15::getGrjx01, bo.getGrjx01());
        lqw.eq(bo.getStatus() != null, Ab15::getStatus, bo.getStatus());
        lqw.eq(bo.getDelStatus() != null, Ab15::getDelStatus, bo.getDelStatus());
        lqw.eq(StringUtils.isNotBlank(bo.getFileurl()), Ab15::getFileurl, bo.getFileurl());
        return lqw;
    }

    /**
     * 新增个人账户基金转入转出信息（转出转入人员）
     *
     * @param bo 个人账户基金转入转出信息（转出转入人员）
     * @return 是否新增成功
     */
    @Override
    public Boolean insertByBo(Ab15Bo bo) {
        Ab15 add = MapstructUtils.convert(bo, Ab15.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改个人账户基金转入转出信息（转出转入人员）
     *
     * @param bo 个人账户基金转入转出信息（转出转入人员）
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(Ab15Bo bo) {
        Ab15 update = MapstructUtils.convert(bo, Ab15.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(Ab15 entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 校验并批量删除个人账户基金转入转出信息（转出转入人员）信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteByIds(ids) > 0;
    }
}
